package my.android.realstories;

import android.app.Activity;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
import android.widget.Toast;

public class CatalogueActivity extends Activity implements OnClickListener {
	
	@Override
    public void onCreate(Bundle savedInstanceState) {
		
        super.onCreate(savedInstanceState);
        setContentView(R.layout.catalogue);        
        
        // check whether there is an internet connection
        checkConnection();
        
        HttpHandler hHandler = new HttpHandler();
        String str = "";
        
        try {
			str = hHandler.getHttpData("http://erostory.cata123.info/server.php?action=get_categories");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
        
/*        LayoutParams lpView = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
                
        TextView tv = new TextView(this);
        tv.setText(str);
        tv.setLayoutParams(lpView);
        linLayout.addView(tv);
*/
        TextView myTextView = (TextView) findViewById(R.id.textView);
        myTextView.setText(str);
        
    }
	
	private void checkConnection() {
		
        Context ctx = getApplicationContext();
        ConnectivityManager conMgr =  (ConnectivityManager)ctx.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo i = conMgr.getActiveNetworkInfo();
        
        if ((i == null) || (!i.isConnected()) || (!i.isAvailable())) {
        	
        	Toast.makeText(getApplicationContext(), "Sorry, No internet connectivity found", Toast.LENGTH_SHORT).show();
        } else {
        	
        	Toast.makeText(getApplicationContext(), "You have internet connectivity", Toast.LENGTH_SHORT).show();
        }
	}
 
  
  @Override
  public void onClick(View v) {
    
  }
}
